home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 3409 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.9 KB

  1. Path: news.compuserve.com!newsmaster
  2. From: 73700.776@compuserve.com (Walter C. Riley)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Using templates in BC++ 4.5
  5. Date: Tue, 23 Jan 1996 21:37:48 GMT
  6. Organization: CompuServe Incorporated
  7. Message-ID: <4e3khc$90r@dub-news-svc-6.compuserve.com>
  8. References: <31050C2D.674C@tribeca.ios.com>
  9. NNTP-Posting-Host: ad45-166.compuserve.com
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. John Leonard <leonardj@tribeca.ios.com> wrote:
  13.  
  14. >I wrote a windows program, in BC++ 4.52, that uses class templates. 
  15. >The template declarations are in a header file and the function 
  16. >definitions are in a cpp file which includes the header file. The cpp 
  17. >file compiled fine, but the project window showed that the code size 
  18. >equaled zero and when I tried to build and link the entire project I got 
  19. >linker error messages that the member functions of the class were 
  20. >undefined. I then changed the code so that the classes weren't templates 
  21. >and the project was built and ran fine. My question is: how can I use 
  22. >class templates in my program?
  23.  
  24. John,
  25.  
  26. You want to remember that when you write a template class, you are not
  27. giving the compiler instructions on how to build objects from a class,
  28. instead you are telling the compiler how to first generate the
  29. specific class declarations themselves -- the code is then generated
  30. using these newly created specific declarations. Borland, by default,
  31. uses smart templates  where code is only generated in a module when an
  32. object of the template class is created. If you are writing general
  33. purpose code, where you don't know exactly what classes will be built
  34. from your templates, then you will want all the code of your template
  35. classes in the header file, so that when the compiler needs to
  36. generate a specific instance of the template, it has the full details
  37. of how to do so. See the STL for good examples of template code.
  38.  
  39. Good luck,
  40. Walt
  41.  
  42.  
  43.